home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6750 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  70 lines

  1. Path: ix.netcom.com!netnews
  2. From: wzjn@ix.netcom.com (KPN )
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Confusion as to the proper use of MODULAS
  5. Date: 14 Feb 1996 20:49:34 GMT
  6. Organization: Netcom
  7. Message-ID: <4fthsu$1kl@ixnews7.ix.netcom.com>
  8. References: <4fr8be$ass@news.iconn.net> <31224679.6193@born.com>
  9. NNTP-Posting-Host: ix-frm-ma1-03.ix.netcom.com
  10. X-NETCOM-Date: Wed Feb 14 12:49:34 PM PST 1996
  11.  
  12. Confusion as to the proper use of MODULAS
  13.  
  14. Very confused. Just as I think IÆve got it correct, I make-up a new
  15. test, the results of which leave me mixed-up again.
  16.  
  17. To begin with, this is the first rule I found out:
  18.  
  19. Modulas operator simply shows:  *** AFTER *** you divide, what is the
  20. remainder?
  21. EXAMPLE of this:
  22.     9 % 7 = ?
  23.     9 divided by 7 yields a remainder of 2
  24.     9 % 7 = 2
  25.  
  26. 1) MODULAS means divide a number and give me the left over number. OK -
  27. not bad.
  28.  
  29. Next rule:
  30. If the number to be divided is smaller than the number to divide by,
  31. the result will always be the number being divided
  32. EXAMPLE of this:
  33.  
  34.    9 % 12 = ?
  35.    can not divide 9 by a larger number
  36.    9 % 12 = 9
  37. Now I have rule #2
  38.  
  39. 2) If the number to be divided is smaller than the nuber to be used as
  40. a divisor, the result is the original number. OK - again, not bad.
  41.  
  42. Here, begin my troubles: using MODULAS in an IF statement.
  43.  
  44. I made up a test to see if a number I inputted was a 7. Sample code:
  45.  
  46.    if (number % 7)
  47.       printf("Not a 7\n");
  48.    else
  49.       printf("First integer was a 7\n");
  50.  
  51. So, if the number WAS a 7, the ELSE would take over. OK. But, when I
  52. enter in a ZERO, it still tells me that the number was a seven?
  53.  
  54. Am I going in the right direction? Can someone tell me what IÆm doing
  55. incorrectly, or where IÆm straying? WhatÆs the rule here for using MOD
  56. in an IF statement?
  57.  
  58. Thank you for your help,
  59. kevin
  60.  
  61.  
  62.  
  63. "When their numbers dwindled from 50 down to 8, the remaining dwarfs
  64. began to suspect 'Hungry'."
  65.  
  66.  
  67.  
  68.  
  69.  
  70.